/**
 * 报表设计公司(2011)
 */
package com.reportgear.report.view.grid.util;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.reportgear.report.core.api.compare.ComparatorUtils;
import com.reportgear.report.model.cell.Cell;
import com.reportgear.report.model.cell.DefaultCell;
import com.reportgear.report.model.cell.painter.CellPainter;
import com.reportgear.report.model.cell.painter.CellPainterManager;
import com.reportgear.report.model.cell.style.BorderStyle;
import com.reportgear.report.model.cell.style.FontStyle;
import com.reportgear.report.model.cell.style.Style;
import com.reportgear.report.model.cell.style.TextStyle;
import com.reportgear.report.model.cell.style.background.Background;
import com.sot.core.util.StringUtils;

/**
 * 绘制使用类
 * 
 * @version 1.0 2011-3-18
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ANNCSR 2.0
 */
public class PaintUtils {
	private static final Logger logger = LoggerFactory.getLogger(PaintUtils.class.getName());
	public static final int Cell_Mark_Size = 6;
	public static final Color Cell_HightLight_Mark_Color = Color.RED;
	public static final Color Cell_Present_Mark_Color = Color.CYAN;
	public static final Color Cell_Pagination_Mark_Color = Color.GREEN;
	public static final Color Cell_Write_Mark_Color = Color.BLUE;
	public static final Color Cell_ConditionFilter_Mark_Color = Color.ORANGE;
	private static Hashtable fontAttributeMapCache = new Hashtable();
	private static Rectangle2D tempRectangle2D = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);

	/**
	 * 绘制单元格
	 * 
	 * @param g2
	 *            绘图对象
	 * @param cell
	 *            单元格
	 * @param rect
	 *            区域
	 */
	public static void paintCellElement(Graphics g, Cell cell, Rectangle rect) {
		if (!(cell instanceof DefaultCell)) {
			return;
		}

		Style style = cell.getStyle();
		if (style == null) {
			style = Style.DEFAULT_STYLE;
		}

		// TODO 绘制背景
		Object value = cell.getValue();
		if (value != null) {
			CellPainter painter = CellPainterManager.INSTANCE.getCellPainter(value);
			painter.paint(g, rect, cell);
		}

		paintBorder((Graphics2D) g, style, rect);
	}

	/**
	 * 绘制单元格标志
	 * 
	 * @param g2
	 *            绘图对象
	 * @param cell
	 *            单元格
	 * @param rect
	 *            区域
	 */
	public static void paintCellElementFlag(Graphics2D g2, DefaultCell cell, Rectangle rect) {
		painCellElementTypeFlag(g2, cell, rect);
	}

	/**
	 * 绘制背景
	 * 
	 * @param g2
	 *            绘图对象
	 * @param style
	 *            样式
	 * @param width
	 *            宽度
	 * @param height
	 *            高度
	 */
	public static void paintBackground(Graphics2D g2, Style style, double width, double height) {
		if (style == null) {
			return;
		}
		Background background = style.getBackground();
		if (background == null) {
			return;
		}
		tempRectangle2D.setRect(0.0D, 0.0D, width, height);
		background.paint(g2, tempRectangle2D);
	}

	// public static void paintBackground(Graphics2D paramGraphics2D, Style
	// paramStyle, Rectangle paramRectangle1, Rectangle paramRectangle2) {
	// if (paramStyle == null) {
	// paramStyle = Style.DEFAULT_STYLE;
	// }
	// Background localBackground = paramStyle.getBackground();
	// if (localBackground == null) {
	// return;
	// }
	// localBackground.paint(paramGraphics2D, new Rectangle(paramRectangle1.x +
	// paramRectangle2.x, paramRectangle1.y + paramRectangle2.y,
	// paramRectangle2.width, paramRectangle2.height));
	// }
	/**
	 * 相对当前原点绘制边框
	 * 
	 * @param g2
	 *            绘图对象
	 * @param style
	 *            样式
	 * @param width
	 *            宽度
	 * @param height
	 *            高度
	 */
	public static void paintBorder(Graphics2D g2, Style style, double width, double height) {
		if (style == null) {
			return;
		}
		BorderStyle border = style.getBorderStyle();

		int lineSize = 0;
		int offsetLeft = 0;
		int offsetRight = 0;
		int offsetTop = 0;
		int offsetBottom = 0;

		if (border.getLeftStyle() != 0) {
			lineSize = GraphHelper.getLineStyleSize(border.getLeftStyle());
			offsetLeft = lineSize / 2;

		}
		if (border.getRightStyle() != 0) {
			lineSize = GraphHelper.getLineStyleSize(border.getRightStyle());
			offsetRight = lineSize / 2;
		}

		if (border.getTopStyle() != 0) {
			lineSize = GraphHelper.getLineStyleSize(border.getTopStyle());
			offsetTop = lineSize / 2;
		}
		if (border.getBottomStyle() != 0) {
			lineSize = GraphHelper.getLineStyleSize(border.getBottomStyle());
			offsetBottom = lineSize / 2;
		}
		if (border.getTopStyle() != 0) {
			g2.setPaint(border.getTopColor());
			GraphHelper.drawLine(g2, 0 - offsetLeft, 0.0D, width + offsetRight, 0.0D, border.getTopStyle());
		}
		if (border.getLeftStyle() != 0) {
			g2.setPaint(border.getLeftColor());
			GraphHelper.drawLine(g2, 0.0D, 0 - offsetTop, 0.0D, height + offsetBottom, border.getLeftStyle());
		}
		if (border.getBottomStyle() != 0) {
			g2.setPaint(border.getBottomColor());
			GraphHelper.drawLine(g2, 0 - offsetLeft, height, width + offsetRight, height, border.getBottomStyle());
		}
		if (border.getRightStyle() != 0) {
			g2.setPaint(border.getRightColor());
			GraphHelper.drawLine(g2, width, 0 - offsetTop, width, height + offsetBottom, border.getRightStyle());
		}
	}

	/**
	 * 绘制边框
	 * 
	 * @param g2
	 *            图形面板
	 * @param style
	 *            样式
	 * @param rect
	 *            矩形区域
	 * @since 1.0
	 */
	public static void paintBorder(Graphics2D g2, Style style, Rectangle rect) {
		g2.translate(rect.x, rect.y);

		if (style == null) {
			style = Style.DEFAULT_STYLE;
		}
		BorderStyle border = style.getBorderStyle();

		int width = rect.width;
		int height = rect.height;
		int offsetLeft = 0;
		int offsetRigth = 0;
		int offsetTop = 0;
		int offsetBottom = 0;
		int lineSize;

		if (border.getLeftStyle() != 0) {
			lineSize = GraphHelper.getLineStyleSize(border.getLeftStyle());
			offsetLeft = lineSize / 2;
		}
		if (border.getRightStyle() != 0) {
			lineSize = GraphHelper.getLineStyleSize(border.getRightStyle());
			offsetRigth = lineSize / 2;
		}

		if (border.getTopStyle() != 0) {
			lineSize = GraphHelper.getLineStyleSize(border.getTopStyle());
			offsetTop = lineSize / 2;
		}
		if (border.getBottomStyle() != 0) {
			lineSize = GraphHelper.getLineStyleSize(border.getBottomStyle());
			offsetBottom = lineSize / 2;
		}
		if (border.getTopStyle() != 0) {
			g2.setPaint(border.getTopColor());
			GraphHelper.drawLine(g2, 0 - offsetLeft, 0.0D, width + offsetRigth, 0.0D, border.getTopStyle());
		}
		if (border.getLeftStyle() != 0) {
			g2.setPaint(border.getLeftColor());
			GraphHelper.drawLine(g2, 0.0D, 0 - offsetTop, 0.0D, height + offsetBottom, border.getLeftStyle());
		}
		if (border.getBottomStyle() != 0) {
			g2.setPaint(border.getBottomColor());
			GraphHelper.drawLine(g2, 0 - offsetLeft, height, width + offsetRigth, height, border.getBottomStyle());
		}
		if (border.getRightStyle() != 0) {
			g2.setPaint(border.getRightColor());
			GraphHelper.drawLine(g2, width, 0 - offsetTop, width, height + offsetBottom, border.getRightStyle());
		}

		g2.translate(-rect.x, -rect.y);
	}

	/**
	 * 对象转化为文本
	 * 
	 * @param o
	 *            对象
	 * @param formatStr
	 *            格式化串
	 * @return 格式化后结果文本
	 */
	public static String valueToText(Object o, String formatStr) {
		Object obj = o;
		String str = null;
		// if (o != null) {
		// if (StringUtils.isEmpty(formatStr)) {
		// str = Utils.objectToString(obj);
		// } else {
		// str = Formatter.format(o, formatStr);
		// }
		// } else {
		// str = "";
		// }
		return str;
	}

	/**
	 * 判断是否字母
	 * 
	 * @param c
	 *            char
	 * @return 是否字母
	 */
	public static boolean isLetter(char c) {
		return (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')));
	}

	/**
	 * 字符串自动分行时，根据宽度对字符进行分割
	 * 
	 * @param text
	 *            显示的字符串
	 * @param style
	 *            样式
	 * @param width
	 *            宽度
	 * @return 分割后的字符串列表
	 */
	public static List getLineTextList(String text, Style style, double width) {
		List lineList = new ArrayList();
		if ((text == null) || (text.length() <= 0)) {
			return lineList;
		}
		if (style == null) {
			style = Style.DEFAULT_STYLE;
		}
		// //旋转字符串不处理
		// if (style.getRotation() != 0) {
		// lineList.add(text);
		// return lineList;
		// }
		FontStyle font = style.getFontStyle();
		FontMetrics fm = GraphHelper.getFontMetrics(font);

		// 如果不是自动换行，查找里面是否有换行符,根据换行符换行
		if (style.getTextStyle() != TextStyle.WORDWRAP) {
			StringBuffer buffer1 = new StringBuffer();
			for (int i = 0; i < text.length(); i++) {
				char c = text.charAt(i);
				if (c == '\\') {
					if ((i < text.length() - 1) && (text.charAt(i + 1) == 'n')) {
						++i;
						lineList.add(buffer1.toString());
						buffer1.delete(0, buffer1.length());
					} else {
						buffer1.append(c);
					}
				} else if (c == '\n') {
					lineList.add(buffer1.toString());
					buffer1.delete(0, buffer1.length());
				} else {
					buffer1.append(c);
				}
			}
			if (buffer1.length() > 0) {
				lineList.add(buffer1.toString());
				buffer1.delete(0, buffer1.length());
			}
			return lineList;
		}

		// 自动计算换行
		double textWidth = width - style.getPaddingLeft() - style.getPaddingRight();
		int j = 0;
		StringBuffer buffer2 = new StringBuffer();
		StringBuffer buffer3 = new StringBuffer();
		int tempWidth = 0;
		for (int i = 0; i < text.length(); i++) {
			if ((i > 0) && (isLetter(text.charAt(i))) && (isLetter(text.charAt(i - 1)))) {
				if (tempWidth + fm.charWidth(text.charAt(i)) > textWidth) {
					if (j > 0) {
						lineList.add(buffer2.toString());
						buffer2.delete(0, buffer2.length());
						j = 0;
					}
					lineList.add(buffer3.toString());
					buffer3.delete(0, buffer3.length());
					tempWidth = 0;
				}
				buffer3.append(text.charAt(i));
				tempWidth += fm.charWidth(text.charAt(i));
			} else if (text.charAt(i) == '\n') {
				if ((j + tempWidth > textWidth) && (buffer2.length() > 0)) {
					lineList.add(buffer2.toString());
					lineList.add(buffer3.toString());
				} else {
					buffer2.append(buffer3);
					lineList.add(buffer2.toString());
				}
				buffer2.delete(0, buffer2.length());
				j = 0;
				buffer3.delete(0, buffer3.length());
				tempWidth = 0;
			} else if ((text.charAt(i) == '\\') && (i < text.length() - 1) && (text.charAt(i + 1) == 'n')) {
				++i;
				if ((j + tempWidth > textWidth) && (buffer2.length() > 0)) {
					lineList.add(buffer2.toString());
					lineList.add(buffer3.toString());
				} else {
					buffer2.append(buffer3);
					lineList.add(buffer2.toString());
				}
				buffer2.delete(0, buffer2.length());
				j = 0;
				buffer3.delete(0, buffer3.length());
				tempWidth = 0;
			} else {
				if ((text.charAt(i) == '\\') && (i + 1 < text.length()) && (text.charAt(i + 1) == '\\')) {
					++i;
				}
				if ((j + tempWidth > textWidth) && (buffer2.length() > 0)) {
					lineList.add(buffer2.toString());
					buffer2.delete(0, buffer2.length());
					j = 0;
				}
				buffer2.append(buffer3);
				j += tempWidth;
				buffer3.delete(0, buffer3.length());
				tempWidth = 0;
				buffer3.append(text.charAt(i));
				tempWidth = fm.charWidth(text.charAt(i));
			}
		}
		if ((j + tempWidth > textWidth) && (buffer2.length() > 0)) {
			lineList.add(buffer2.toString());
			lineList.add(buffer3.toString());
		} else {
			buffer2.append(buffer3);
			lineList.add(buffer2.toString());
		}
		return lineList;
	}

	// public static List getLineTextList_Vertical(String str, Style style,
	// double width) {
	// char c;
	// int i1;
	// int i2;
	//
	// ArrayList lineList = new ArrayList();
	// if ((str == null) || (str.length() <= 0)) {
	// return lineList;
	// }
	// if (style == null) {
	// style = Style.DEFAULT_STYLE;
	// return getLineTextList(str, style, width);
	// }
	// ArrayList localArrayList2 = new ArrayList();
	// int i = 0;
	// ReportFont localFRFont = style.getFRFont();
	// FontMetrics localFontMetrics = GraphHelper.getFontMetrics(localFRFont);
	// int j = localFontMetrics.getHeight();
	// TextStyle k = style.getTextStyle();
	// if (k == TextStyle.WORDWARP) {
	// double d = width - style.getPaddingLeft() - style.getPaddingRight();
	// i1 = 1;
	// int i4 = 0;
	// int i5 = 0;
	// StringBuffer localStringBuffer3 = new StringBuffer();
	// for (int i6 = 0; i6 < str.length(); ++i6) {
	// i2 = str.charAt(i6);
	// if ((i2 == 32) && (i1 == 0)) {
	// continue;
	// }
	// if (i2 == 10) {
	// localArrayList2.add(localStringBuffer3.toString());
	// localStringBuffer3.delete(0, localStringBuffer3.length());
	// i5 = 0;
	// i4 = 0;
	// } else {
	// if (i2 != 32) {
	// i1 = 0;
	// }
	// if (i2 == 92) {
	// if ((i6 + 1 < str.length()) && (str.charAt(i6 + 1) == 'n')) {
	// ++i6;
	// localArrayList2.add(localStringBuffer3.toString());
	// localStringBuffer3.delete(0, localStringBuffer3.length());
	// i5 = 0;
	// i = Math.max(i, ++i4);
	// i4 = 0;
	// continue;
	// }
	// localStringBuffer3.append(i2);
	// i5 += j;
	// i = Math.max(i, ++i4);
	// } else {
	// localStringBuffer3.append(i2);
	// i5 += j;
	// i = Math.max(i, ++i4);
	// }
	// if (i5 <= d) {
	// continue;
	// }
	// localArrayList2.add(localStringBuffer3.substring(0,
	// localStringBuffer3.length() - 1));
	// localStringBuffer3.delete(0, localStringBuffer3.length() - 1);
	// i5 = j;
	// i = Math.max(i, i4 - 1);
	// i4 = 1;
	// }
	// }
	// localArrayList2.add(localStringBuffer3.toString());
	// } else {
	// StringBuffer localStringBuffer1 = new StringBuffer();
	// for (i1 = 0; i1 < str.length(); ++i1) {
	// if (i1 >= str.length()) {
	// continue;
	// }
	// c = str.charAt(i1);
	// if (c == '\n') {
	// continue;
	// }
	// if (c == '\\') {
	// if ((i1 + 1 < str.length()) && (str.charAt(i1 + 1) == 'n')) {
	// ++i1;
	// } else {
	// localStringBuffer1.append(c);
	// ++i;
	// }
	// } else {
	// localStringBuffer1.append(c);
	// ++i;
	// }
	// }
	// localArrayList2.add(localStringBuffer1.toString());
	// localStringBuffer1.delete(0, localStringBuffer1.length());
	// }
	// for (int l = 0; l < i; ++l) {
	// StringBuffer localStringBuffer2 = new StringBuffer();
	// if (style.getTextDirection() == 1) {
	// for (i2 = 0;; ++i2) {
	// if (i2 >= localArrayList2.size()) {
	// lineList.add(localStringBuffer2.toString());
	// break;
	// }
	// if (((String) localArrayList2.get(i2)).length() > l) {
	// c = ((String) localArrayList2.get(i2)).charAt(l);
	// localStringBuffer2.append(c);
	// if (localFontMetrics.charWidth(c) != 6) {
	// continue;
	// }
	// localStringBuffer2.append(' ');
	// } else {
	// localStringBuffer2.append(' ');
	// localStringBuffer2.append(' ');
	// }
	// }
	// }
	// for (int i3 = localArrayList2.size() - 1; i3 >= 0; --i3) {
	// if (((String) localArrayList2.get(i3)).length() > l) {
	// c = ((String) localArrayList2.get(i3)).charAt(l);
	// localStringBuffer2.append(c);
	// if (localFontMetrics.charWidth(c) != 6) {
	// continue;
	// }
	// localStringBuffer2.append(' ');
	// } else {
	// localStringBuffer2.append(' ');
	// localStringBuffer2.append(' ');
	// }
	// }
	//
	// lineList.add(localStringBuffer2.toString());
	// }
	// return lineList;
	// }
	//
	// public static double getPreferredWidth(CellElement paramCellElement, int
	// paramInt) {
	// if (paramCellElement == null) {
	// return 0.0D;
	// }
	// Object localObject = paramCellElement.getValue();
	// if (localObject instanceof Formula) {
	// localObject = ((Formula) localObject).getResult();
	// }
	// Style localStyle = paramCellElement.getStyle();
	// String str = valueToText(localObject, localStyle.getFormat());
	// FRFont localFRFont = localStyle.getFRFont();
	// FontMetrics localFontMetrics = GraphHelper.getFontMetrics(localFRFont);
	// return (localFontMetrics.stringWidth(str) + 4);
	// }
	//
	// public static int analyzeCellElementPreferredHeight(CellElement
	// paramCellElement, int paramInt) {
	// Object localObject = paramCellElement.getValue();
	// Style localStyle = paramCellElement.getStyle();
	// if (localObject instanceof Formula) {
	// if (((Formula) localObject).getResult() != null) {
	// localObject = ((Formula) localObject).getResult();
	// } else {
	// localObject = "";
	// }
	// }
	// String str = valueToText(localObject, localStyle.getFormat());
	// return analyzeCellElementPreferredHeight(str, localStyle, paramInt);
	// }
	//
	// public static int analyzeCellElementPreferredHeight(String paramString,
	// Style paramStyle, int paramInt) {
	// if (paramStyle == null) {
	// paramStyle = Style.DEFAULT_STYLE;
	// }
	// if ((paramString == null) || (paramString.length() <= 0)) {
	// return 0;
	// }
	// if (paramStyle.getRotation() != 0) {
	// return (int) GraphHelper.stringDimension(paramString,
	// paramStyle.getFRFont(), -paramStyle.getRotation(),
	// BaseCoreConstants.DEFAULT_FRC).getHeight();
	// }
	// List localList = getLineTextList(paramString, paramStyle, paramInt);
	// FRFont localFRFont = paramStyle.getFRFont();
	// FontMetrics localFontMetrics = GraphHelper.getFontMetrics(localFRFont);
	// double d = localFontMetrics.getHeight();
	// return ((int) d * localList.size());
	// }
	//
	// public static Style modCellStyleString(int paramInt1, int paramInt2,
	// String paramString, Style paramStyle) {
	// List localList;
	// FRFont localFRFont;
	// Object localObject;
	// if (paramStyle.getVerticalText() == 1) {
	// localList = getLineTextList_Vertical(paramString, paramStyle, paramInt2);
	// } else {
	// localList = getLineTextList(paramString, paramStyle, paramInt1);
	// }
	// if (paramStyle.getTextStyle() == 2) {
	// localFRFont = paramStyle.getFRFont();
	// int i = 0;
	// localObject = "";
	// for (int j = 0; j < localList.size(); ++j) {
	// if (GraphHelper.getFontMetrics(localFRFont).stringWidth((String)
	// localList.get(j)) <= i) {
	// continue;
	// }
	// localObject = (String) localList.get(j);
	// i = GraphHelper.getFontMetrics(localFRFont).stringWidth((String)
	// localList.get(j));
	// }
	// if (i > 0) {
	// if (i > paramInt1 - paramStyle.getPaddingLeft() -
	// paramStyle.getPaddingRight()) {
	// do {
	// if (localFRFont.getSize() <= 1) {
	// break label920;
	// }
	// localFRFont = localFRFont.applySize(localFRFont.getSize() - 1);
	// i = GraphHelper.getFontMetrics(localFRFont).stringWidth((String)
	// localObject);
	// } while (i > paramInt1 - paramStyle.getPaddingLeft() -
	// paramStyle.getPaddingRight());
	// paramStyle = paramStyle.deriveFRFont(localFRFont);
	// } else {
	// do {
	// if ((i >= paramInt1 - paramStyle.getPaddingLeft() -
	// paramStyle.getPaddingRight()) || (localFRFont.getSize() >= 100)) {
	// break label920;
	// }
	// localFRFont = localFRFont.applySize(localFRFont.getSize() + 1);
	// i = GraphHelper.getFontMetrics(localFRFont).stringWidth((String)
	// localObject);
	// } while (i <= paramInt1 - paramStyle.getPaddingLeft() -
	// paramStyle.getPaddingRight());
	// localFRFont = localFRFont.applySize(localFRFont.getSize() - 1);
	// i = GraphHelper.getFontMetrics(localFRFont).stringWidth((String)
	// localObject);
	// paramStyle = paramStyle.deriveFRFont(localFRFont);
	// }
	// }
	// } else if (paramStyle.getTextStyle() == 3) {
	// int i1;
	// localFRFont = paramStyle.getFRFont();
	// ArrayList localArrayList = new ArrayList();
	// Style localStyle = Style.DEFAULT_STYLE;
	// localStyle = localStyle.deriveTextStyle(0);
	// int k = GraphHelper.getFontMetrics(localFRFont).getHeight();
	// for (int l = 0; l < localList.size(); ++l) {
	// localStyle = localStyle.deriveFRFont(localFRFont);
	// localObject = getLineTextList((String) localList.get(l), localStyle,
	// paramInt1);
	// for (i1 = 0; i1 < ((List) localObject).size(); ++i1) {
	// localArrayList.add((String) ((List) localObject).get(i1));
	// }
	// }
	// if (localArrayList.size() * k > paramInt2) {
	// do {
	// if (localFRFont.getSize() <= 1) {
	// break label920;
	// }
	// localFRFont = localFRFont.applySize(localFRFont.getSize() - 1);
	// localArrayList.clear();
	// for (l = 0; l < localList.size(); ++l) {
	// localStyle = localStyle.deriveFRFont(localFRFont);
	// localObject = getLineTextList((String) localList.get(l), localStyle,
	// paramInt1);
	// for (i1 = 0; i1 < ((List) localObject).size(); ++i1) {
	// localArrayList.add((String) ((List) localObject).get(i1));
	// }
	// }
	// k = GraphHelper.getFontMetrics(localFRFont).getHeight();
	// } while (localArrayList.size() * k > paramInt2);
	// paramStyle = paramStyle.deriveFRFont(localFRFont);
	// } else {
	// do {
	// if ((localArrayList.size() * k >= paramInt2) || (localFRFont.getSize() >=
	// 100)) {
	// break label920;
	// }
	// localFRFont = localFRFont.applySize(localFRFont.getSize() + 1);
	// localArrayList.clear();
	// for (l = 0; l < localList.size(); ++l) {
	// localStyle = localStyle.deriveFRFont(localFRFont);
	// localObject = getLineTextList((String) localList.get(l), localStyle,
	// paramInt1);
	// for (i1 = 0; i1 < ((List) localObject).size(); ++i1) {
	// localArrayList.add((String) ((List) localObject).get(i1));
	// }
	// }
	// k = GraphHelper.getFontMetrics(localFRFont).getHeight();
	// } while (localArrayList.size() * k <= paramInt2);
	// localFRFont = localFRFont.applySize(localFRFont.getSize() - 1);
	// paramStyle = paramStyle.deriveFRFont(localFRFont);
	// localArrayList.clear();
	// for (l = 0; l < localList.size(); ++l) {
	// localStyle = localStyle.deriveFRFont(localFRFont);
	// localObject = getLineTextList((String) localList.get(l), localStyle,
	// paramInt1);
	// for (i1 = 0; i1 < ((List) localObject).size(); ++i1) {
	// localArrayList.add((String) ((List) localObject).get(i1));
	// }
	// }
	// k = GraphHelper.getFontMetrics(localFRFont).getHeight();
	// }
	// }
	// label920:
	// return ((Style) paramStyle);
	// }
	/**
	 * 绘制格式化字符串
	 * 
	 * @param g2
	 *            图形对象
	 * @param rect
	 *            绘制区域
	 * @param content
	 *            内容
	 * @param style
	 *            样式
	 */
	// public static void paintCellStyleString(Graphics2D g2, Rectangle rect,
	// String content, Style style) {
	// double w = rect.width;
	// double h = rect.height;
	// double ascent = 0;
	// double x = 0;
	// double y = 0;
	//
	// if (StringUtils.isEmpty(content)) {
	// return;
	// }
	//
	// if (style == null) {
	// style = Style.DEFAULT_STYLE;
	// }
	//
	// List<String> lines = getLineTextList(content, style, rect.width);
	//
	// FontRenderContext frContext = g2.getFontRenderContext();
	// FontStyle font = style.getFontStyle();
	//
	// // Locale locale = ReportContext.getLocale();
	// // if ((Locale.ENGLISH.equals(locale)) && (((str.startsWith("↓")) ||
	// // (str.startsWith("→"))))) {
	// // font = ReportFont.getInstance("Dialog", font.getStyle(),
	// // font.getSize());
	// // }
	// if (!ComparatorUtils.equals(font, g2.getFont())) {
	// g2.setFont(font);
	// }
	// Color color = font.getForeground();
	// if (!ComparatorUtils.equals(color, g2.getPaint())) {
	// g2.setPaint(color);
	// }
	// FontMetrics fm = g2.getFontMetrics();
	//
	// int count = lines.size();
	// if (count == 0) {
	// return;
	// }
	//
	// Shape oldClip = g2.getClip();
	// g2.clip(rect);
	// g2.translate(rect.x, rect.y);
	//
	// double textH = fm.getHeight();
	// double startY;
	// switch (style.getVerticalAlignment()) {
	// case MIDDLE:
	// startY = (h + style.getSpacingBefore() - textH * count -
	// style.getSpacingAfter()) / 2.0D;
	// break;
	// case TOP:
	// startY = style.getSpacingBefore();
	// break;
	// case BOTTOM:
	// startY = h - textH * count - style.getSpacingAfter();
	// break;
	// default:
	// startY = (h - textH * count) / 2.0D;
	// }
	//
	// for (int i = 0; i < count; i++) {
	// String tmpStr = lines.get(i).trim();
	// GraphHelper.drawString(g2, tmpStr, getDrawStringX(w,
	// fm.stringWidth(tmpStr), style), startY + textH * i
	// + fm.getAscent());
	// }
	// g2.translate(-rect.x, -rect.y);
	// g2.setClip(oldClip);
	// }

	/**
	 * 获取字符串绘制的X位置
	 * 
	 * @param totalWidth
	 *            总宽度
	 * @param stringWidth
	 *            字符串宽度
	 * @param style
	 *            样式
	 * @return X位置
	 */
	private static double getDrawStringX(double totalWidth, double stringWidth, Style style) {
		switch (style.getHorizentalAlignment()) {
		case CENTER:
			return (totalWidth + style.getPaddingLeft() - stringWidth - style.getPaddingRight()) / 2.0D;
		case LEFT:
			return style.getPaddingLeft();
		case RIGHT:
			return totalWidth - stringWidth - style.getPaddingRight();
		default:
			return (totalWidth + style.getPaddingLeft() - stringWidth - style.getPaddingRight()) / 2.0D;
		}
	}

	/**
	 * 绘制单元格对象标记
	 * 
	 * @param g2
	 *            绘图对象
	 * @param element
	 *            元素
	 * @param rect
	 *            矩形区域
	 */
	private static void painCellElementTypeFlag(Graphics2D g2, DefaultCell cell, Rectangle rect) {
		Object o = cell.getValue();

		if ((o == null) || (o instanceof String) || (o instanceof Number)) {
			return;
		}

		int[] xPos = { 0, 0, 8 };
		int[] yPos = { 0, 8, 0 };
		g2.translate(rect.x, rect.y);
		// GraphHelper.drawTriangle(g2, xPos, yPos, Color.RED);
		g2.translate(-rect.x, -rect.y);
	}
	// public static void paintBarcode(Graphics2D paramGraphics2D, int
	// paramInt1, int paramInt2, String paramString, Style paramStyle,
	// BarcodeAttr paramBarcodeAttr)
	// {
	// BarcodeImpl localBarcodeImpl;
	// try
	// {
	// localBarcodeImpl = BarCodeUtils.getBarcodeImpl(paramBarcodeAttr,
	// paramString);
	// }
	// catch (BarcodeException localBarcodeException1)
	// {
	// try
	// {
	// localBarcodeImpl = BarCodeUtils.getBarcodeImpl(new BarcodeAttr(), null);
	// } catch (BarcodeException localBarcodeException2) {
	// FRContext.getLogger().log(Level.WARNING,
	// localBarcodeException2.getMessage(), localBarcodeException2);
	// return;
	// }
	// }
	// if (paramStyle.getFRFont() != null) {
	// localBarcodeImpl.setFont(paramStyle.getFRFont());
	// localBarcodeImpl.setForeground(paramStyle.getFRFont().getForeground());
	// }
	// Background localBackground = paramStyle.getBackground();
	// if ((localBackground != null) && (localBackground instanceof
	// ColorBackground)) {
	// localBarcodeImpl.setBackground(((ColorBackground)
	// localBackground).getColor());
	// }
	// int i = (paramInt1 - localBarcodeImpl.getWidth()) / 2;
	// int j = (paramInt2 - localBarcodeImpl.getHeight()) / 2;
	// localBarcodeImpl.draw(paramGraphics2D, i, j);
	// }
	//
	// public static Map createFontAttributeMap(Font paramFont) {
	// Map localMap = (Map) fontAttributeMapCache.get(paramFont);
	// if (localMap == null) {
	// localMap = paramFont.getAttributes();
	// fontAttributeMapCache.put(paramFont, localMap);
	// }
	// if (paramFont instanceof FRFont) {
	// FRFont localFRFont = (FRFont) paramFont;
	// if (localFRFont.isStrikethrough()) {
	// localMap.put(TextAttribute.STRIKETHROUGH,
	// TextAttribute.STRIKETHROUGH_ON);
	// }
	// }
	// return localMap;
	// }
}
